package network;

import java.net.DatagramPacket;
import java.net.InetAddress;

/**
 * Abstract class that correspond to what we call a "User Signal".
 * A User Signal contains information about a network signal : The
 * sender (or receiver) and the content of the signal.
 */
public abstract class AbstractUserSignal {

	private InetAddress address = null ;

	/**
	 * Create a new AbstractUserSignal according to information 
	 * contained in the packet (only the address).
	 * 
	 * @param packet
	 */
	public AbstractUserSignal (DatagramPacket packet) {
		this.address = packet.getAddress();
	}
	
	/**
	 * Create a new AbstractUserSignal according to specified address.
	 * 
	 * @param address
	 */
	public AbstractUserSignal (InetAddress address) {
		this.address = address ;
	}
	
	/**
	 * @return the user address
	 */
	public InetAddress getAddress () {
		return this.address ;
	}
	
	/**
	 * Serialize the signal into an array of byte according to protocol rules.
	 * 
	 * @return The byte corresponding or null if an error occurred
	 */
	public abstract byte[] serialize () ;
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString () {
		return this.getClass() + " (" + this.address + ")" ;
	}
}
